-
Notifications
You must be signed in to change notification settings - Fork 86
Diana - Pine #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Diana - Pine #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ Really nice work, Diana. Since you chose to do a doubly linked lists, I left a few comments about refactoring some of your methods for doubly linked lists. Let me know what questions you have.
🟢
def __init__(self, value, next_node = None, prev_node = None): | ||
self.value = value | ||
self.next = next_node | ||
self.previous = prev_node #This line because this is a doubly linked list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😎 Ooh doubly linked list
# Space Complexity: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
def get_first(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
# Space Complexity: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
def add_first(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def search(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def length(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
|
||
# method to return the max value in the linked list | ||
# returns the data value and not the node | ||
def find_max(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def delete(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
if new.value == value: | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally try and avoid using break statements unless really necessary. Might you be able to refactor your code to eliminate this?
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪐 Space complexity will be O(n) here because the function creates a helper_list
which will end up holding all the nodes in the linked list
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def reverse(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you have a doubly linked list you also need to think about how you redirect your previous and tail pointers.
No description provided.